
/**
 *
 * @author leon
 */
//import java.awt.Graphics;
//import java.awt.Image;
//import java.awt.image.ImageObserver;
//import java.awt.image.ImageProducer;
import java.awt.MouseInfo;
import java.awt.Point;
import java.util.List;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JRootPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public abstract class JFrame extends javax.swing.JFrame {

    private final String SYS_NEWLINE = System.getProperty("line.separator");

    /**
     * Creates new form JFrame
     */
    public JFrame() {
        setUndecorated(true);
        getRootPane().setWindowDecorationStyle(JRootPane.NONE);
        initComponents();
        //Image background = new Image("images.jpg")
        ComponentMover jframeMover = new ComponentMover(JFrame.class, topBar);
        setIconImage(new ImageIcon("images.jpg").getImage());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        loginBox = new javax.swing.JDialog();
        jTextField1 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        topBarLoginBox = new javax.swing.JPanel();
        exitLoginBoxButton = new javax.swing.JButton();
        titleLoginBox = new javax.swing.JLabel();
        loginButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taskTable = new javax.swing.JTable();
        outputBoxScrollPane = new javax.swing.JScrollPane();
        outputBox = new javax.swing.JTextArea();
        inputBox = new javax.swing.JTextField();
        backgroundLabel = new javax.swing.JLabel();
        topBar = new javax.swing.JPanel();
        syncButton = new javax.swing.JButton();

        loginBox.setUndecorated(true);
        loginBox.setResizable(false);

        jTextField1.setText("jTextField1");

        jPasswordField1.setText("jPasswordField1");

        jLabel2.setText("User Name");

        jLabel4.setText("Password");

        exitLoginBoxButton.setText("exit");
        exitLoginBoxButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitLoginBoxButtonActionPerformed(evt);
            }
        });

        titleLoginBox.setText("Google Account Login");

        javax.swing.GroupLayout topBarLoginBoxLayout = new javax.swing.GroupLayout(topBarLoginBox);
        topBarLoginBox.setLayout(topBarLoginBoxLayout);
        topBarLoginBoxLayout.setHorizontalGroup(
            topBarLoginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topBarLoginBoxLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titleLoginBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(exitLoginBoxButton))
        );
        topBarLoginBoxLayout.setVerticalGroup(
            topBarLoginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(topBarLoginBoxLayout.createSequentialGroup()
                .addGroup(topBarLoginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(exitLoginBoxButton)
                    .addComponent(titleLoginBox))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        loginButton.setText("Login");
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout loginBoxLayout = new javax.swing.GroupLayout(loginBox.getContentPane());
        loginBox.getContentPane().setLayout(loginBoxLayout);
        loginBoxLayout.setHorizontalGroup(
            loginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loginBoxLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(loginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(loginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(loginBoxLayout.createSequentialGroup()
                        .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(loginButton))
                    .addGroup(loginBoxLayout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(topBarLoginBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        loginBoxLayout.setVerticalGroup(
            loginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(loginBoxLayout.createSequentialGroup()
                .addComponent(topBarLoginBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(loginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(loginBoxLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(loginButton))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setIconImage(new ImageIcon(getClass().getResource("/resource/images.jpg")).getImage());
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setOpaque(false);
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jScrollPane1.setOpaque(false);

        taskTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "No.", "Task", "Date", "Status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        taskTable.setOpaque(false);
        jScrollPane1.setViewportView(taskTable);
        taskTable.getColumnModel().getColumn(0).setMaxWidth(50);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 150, 390, 100));

        outputBox.setColumns(20);
        outputBox.setRows(5);
        outputBoxScrollPane.setViewportView(outputBox);

        jPanel1.add(outputBoxScrollPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 10, 390, 130));

        inputBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputBoxActionPerformed(evt);
            }
        });
        jPanel1.add(inputBox, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 270, 389, 20));

        backgroundLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/images.jpg"))); // NOI18N
        jPanel1.add(backgroundLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, 270));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(1, 23, 390, 290));

        javax.swing.GroupLayout topBarLayout = new javax.swing.GroupLayout(topBar);
        topBar.setLayout(topBarLayout);
        topBarLayout.setHorizontalGroup(
            topBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        topBarLayout.setVerticalGroup(
            topBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        getContentPane().add(topBar, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 20));

        syncButton.setText("Sync");
        syncButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                syncButtonActionPerformed(evt);
            }
        });
        getContentPane().add(syncButton, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 320, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inputBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputBoxActionPerformed
        String userInputString = inputBox.getText();

        inputFromUser(userInputString);
        inputBox.setText(null);
        this.appendOutput(userInputString);
    }//GEN-LAST:event_inputBoxActionPerformed

    private void syncButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_syncButtonActionPerformed
        this.pressSyncButton();
    }//GEN-LAST:event_syncButtonActionPerformed

    private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed
        pressLoginButton();
    }//GEN-LAST:event_loginButtonActionPerformed

    private void exitLoginBoxButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitLoginBoxButtonActionPerformed
        exitLoginBox();
    }//GEN-LAST:event_exitLoginBoxButtonActionPerformed
    abstract public void inputFromUser(String Input);

    abstract public void pressSyncButton();

    abstract public void pressLoginButton();

    /**
     * 
     * @param outputString
     */
    public void appendOutput(String outputString) {
        outputBox.append(outputString + SYS_NEWLINE);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel backgroundLabel;
    private javax.swing.JButton exitLoginBoxButton;
    private javax.swing.JTextField inputBox;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JDialog loginBox;
    private javax.swing.JButton loginButton;
    private javax.swing.JTextArea outputBox;
    private javax.swing.JScrollPane outputBoxScrollPane;
    private javax.swing.JButton syncButton;
    private javax.swing.JTable taskTable;
    private javax.swing.JLabel titleLoginBox;
    private javax.swing.JPanel topBar;
    private javax.swing.JPanel topBarLoginBox;
    // End of variables declaration//GEN-END:variables

    public void clearOutput() {
        outputBox.setText(null);
    }

    public void popLogin() {
        Point mousePoint = MouseInfo.getPointerInfo().getLocation();
        //loginBox.setWindowDecorationStyle(loginBox.NONE);
        this.setEnabled(false);
        loginBox.setLocation(mousePoint);
        loginBox.setSize(250, 96);
        loginBox.setAlwaysOnTop(true);
        loginBox.setVisible(true);

    }

    public void hideLogin() {
        loginBox.setVisible(false);
        this.setEnabled(true);
        this.toFront();
    }

    private void exitLoginBox() {
        loginBox.setVisible(false);
        this.setEnabled(true);
        this.toFront();
    }

    abstract public void writeTable(List<Task> taskList);
  
    public JTable getListTable(){
        
        return this.taskTable;
        
    }
    public void addRowToModel() {
        DefaultTableModel taskModel = (DefaultTableModel) taskTable.getModel();
        taskModel.addRow(new Object[]{"", "", ""});
    }
}
